<template>
  <div>
    <el-table
      :data="tableData"
      border
      stripe
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="200">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="200">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话"
        width="200">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="300">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        width="300">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间">
      </el-table-column>
    </el-table>
    <el-pagination
      background
      align="right"
      layout="prev, pager, next"
      :total="totals"
      :current-page="currentPage"
      :page-size="pageSize"
      @current-change="pageList">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'FirstTable',
  data () {
    return {
      tableData : [],
      totals:50,
      currentPage:1,
      pageSize:5
    }
  },
  mounted() {
    //第一页加载出来后的数据展示
    this.list()
  },
  methods:{
    pageList(current){
      // 点击页码之后，页码改变的同时，发送axios请求
      this.currentPage = current;
      this.list();
    },
    //发送axios请求，将数据赋值到tableData中
    list(){
      this.$http.post("/dept/queryPage",{"currentPage":this.currentPage, "pageSize":this.pageSize})
        .then(result => {
          //当前对象调用自己的属性就用this
          this.tableData = result.data.rows;
          this.totals = result.data.totals;
          })
        .catch(result => {
          alert("咋搞哒")
      })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
